from selenium import webdriver
import time

# Created with pycharm
# author:ju bai
# Date:2021/7/20
# Time:8:22

driver = webdriver.Chrome();

driver.get("https://www.baidu.com/")
# 浏览器最大化
driver.maximize_window()
# 设置浏览器的宽、高
# driver.set_window_size(400,300)

# title0 = driver.title
# print(title0)
# print(driver.current_url)

driver.find_element_by_id("kw").send_keys("姜云升")
driver.find_element_by_id("su").click()
time.sleep(3)

# # 设置浏览器的前进、后退
# # 后退
# driver.back()
# time.sleep(6)
# # 前进
# driver.forward()
# time.sleep(6)

# 滚动条到浏览器最底端
js = "var q = document.documentElement.scrollTop=10000"
driver.execute_script(js)
time.sleep(6)
# 滚动条到浏览器最顶端
js = "var q = document.documentElement.scrollTop=0"
driver.execute_script(js)
time.sleep(6)
# # 提交表单
# driver.find_element_by_id("su").submit()
# time.sleep(6)
# # 清除文本内容
# driver.find_element_by_id("kw").clear()
#
# time.sleep(3)
# driver.find_element_by_id("kw").send_keys("自白书")
# driver.find_element_by_id("su").click()

# 获得文本信息
# text = driver.find_element_by_id("bottom_layer").text
# print(text)
# # 休眠等待，严格执行设置的的等待时间
# time.sleep(6)
# # 智能等待（隐式等待）
# driver.implicitly_wait(10)
#
# driver.find_element_by_id("kw").send_keys("姜云升")
# driver.find_element_by_id("su").submit()
# # 当页面加载出来再执行，使用隐式等待
# driver.implicitly_wait(8)
# driver.find_element_by_link_text("姜云升 - 百度百科").click()

# time.sleep(10)
# # 打印title
# title = driver.title
# print(title)
# # 打印当前url
# print(driver.current_url)

driver.quit()